package com.orange.score.activity.entry;

import android.content.Context;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import java.util.ArrayList;
import java.util.List;

public class PageableAdapter<T> extends BaseAdapter
{
  public static final int DEFAULT_PAGE_SIZE = 400;
  public Context context;
  public int endIndex;
  public List<T> list = new ArrayList();
  public int pageSize;
  public int startIndex = 0;

  public PageableAdapter(List<T> paramList, Context paramContext)
  {
    this.endIndex = 0;
    this.pageSize = 400;
    this.list = paramList;
    this.context = paramContext;
  }

  public int getCount()
  {
    int i;
    if (this.list.size() == 0)
      i = 0;
    while (true)
    {
      return i;
      i = 1 + this.endIndex - this.startIndex;
    }
  }

  public int getEndIndex()
  {
    return this.endIndex;
  }

  public T getItem(int paramInt)
  {
    Object localObject;
    if (paramInt <= this.list.size() - 1)
      localObject = this.list.get(paramInt + this.startIndex);
    while (true)
    {
      return localObject;
      localObject = null;
    }
  }

  public long getItemId(int paramInt)
  {
    long l;
    if (paramInt < this.list.size() - 1)
      l = paramInt + this.startIndex;
    while (true)
    {
      return l;
      l = -1L;
    }
  }

  public List<T> getList()
  {
    return this.list;
  }

  public int getPageSize()
  {
    return this.pageSize;
  }

  public int getStartIndex()
  {
    return this.startIndex;
  }

  public View getView(int paramInt, View paramView, ViewGroup paramViewGroup)
  {
    return null;
  }

  public boolean nextPage()
  {
    int k;
    int i = this.list.size();
    int j = this.endIndex;
    if (i == 0)
      k = 0;
    while (true)
    {
      return k;
      if (this.endIndex + this.pageSize >= i)
        this.endIndex = (i - 1);
      while (true)
      {
        while (true)
        {
          printListData();
          if (j == this.endIndex)
            break label76;
          k = 1;
        }
        this.endIndex += this.pageSize;
      }
      label76: k = 0;
    }
  }

  public void onScroll(int paramInt1, int paramInt2)
  {
    if ((paramInt1 + paramInt2 == getCount()) && (nextPage()))
      notifyDataSetChanged();
  }

  protected void printListData()
  {
    Log.d("PageableAdapter", "List size = " + this.list.size() + ", start = " + this.startIndex + ", end = " + this.endIndex + ", count = " + getCount());
  }

  public void setEndIndex(int paramInt)
  {
    this.endIndex = paramInt;
  }

  public void setList(List<T> paramList)
  {
    this.list = paramList;
  }

  public void setPageSize(int paramInt)
  {
    this.pageSize = paramInt;
  }

  public void setStartIndex(int paramInt)
  {
    this.startIndex = paramInt;
  }

  public void updateList(List<T> paramList)
  {
    this.list = paramList;
    int i = this.list.size();
    if (i == 0)
    {
      this.startIndex = 0;
      this.endIndex = 0;
    }
    while (true)
    {
      do
      {
        printListData();
        return;
        this.startIndex = 0;
        this.endIndex = this.pageSize;
      }
      while (this.endIndex <= i - 1);
      this.endIndex = (i - 1);
    }
  }
}